﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MonkeysWithTypeWriters.ServiceContracts;
using MonkeysWithTypewriters.MonkeyProcessing;

namespace MonkeysWithTypewritters.WebService.Controllers
{
    public class MonkeyTextController : ApiController
    {
        /// <summary>
        /// POST api/monkeytext
        /// creates the primate specified by the submission and has the primate create the novel
        /// </summary>
        /// <param name="submission"></param>
        /// <returns></returns>
        public NovelResult Post(NovelSubmission submission)
        {
            DateTime processingBegan = DateTime.Now; 
            var result = new NovelResult
            {
                //Get the correct primate and have it write a novel with the speicified page count
                Text = GetPrimate(submission.TextType).CreateText(submission.PageCount),
                BeganProcessingOn = processingBegan,
                ProcessingCompletedOn = DateTime.Now
            };

            return result;
        }

        private IPrimate GetPrimate(string type)
        {
            switch (type)
            {
                case "Spider Monkey":
                    return new SpiderMonkey();
                case "Orangutan": 
                    return new Orangutan();
                case "Chimpanzee":
                    return new Chimpanzee();
                default:
                    return null;
            }
        }

    }
}
